//
// Created by jingjia on 10/15/21.
//

#include "os.hpp"
#include "osThread.hpp"
#include "thread.hpp"
#include "mutexLocker.h"

void OS::start_thread(Thread* thread) {
    // guard suspend/resume
    OSThread* osthread = thread->osThread();
    osthread->setThreadState(RUNNABLE);
    INFO_PRINT("threadState: RUNNABLE\n");
    pd_start_thread(thread);
}

void OS::pd_start_thread(Thread* thread) {
    OSThread * osthread = thread->osThread();
    assert(osthread->threadState() != INITIALIZED, "just checking");
    Monitor* monitor = osthread->startThreadLock();
    MutexLockerEx ml(monitor);
    monitor->notify();
}